package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

/**
 * Created by pengwan on 2017/8/1.
 * Test Only!
 * 只用于测试中执行sql脚本(生成bean:transactionManager, 详见@SqlConfig(dataSource = "secondaryDS", transactionManager = "secondaryTxManager"))
 */
@Configuration
public class SecondaryDSTxManager {
    @Autowired
    @Qualifier("secondaryDS")
    private DataSource secondaryDS;

    @Bean(name = "secondaryTxManager") @Qualifier("secondaryTxManager")
    public DataSourceTransactionManager secondaryTransactionManager(){
        return new DataSourceTransactionManager(secondaryDS);
    }
}
